package com.clock.controller.stage;

import com.clock.common.domain.R;
import com.clock.service.SignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"前台-签到"})
@RestController
@RequestMapping("/userSign")
public class SignController {

    @Autowired
    SignInService signInStageService;


    /**
     * 前台用户当日签到
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/someday/{userId}")
    @ApiOperation(value = "当日签到", notes = "该用户当日签到")
    public R singleUserSign(@PathVariable("userId") Long userId) throws Exception {

        return signInStageService.insertSignByUserId(userId);
    }

    /**
     * 用户补签
     *
     * @param userId
     * @param day
     * @return
     * @throws Exception
     */
    @PostMapping("/otherday/{userId}/{day}")
    @ApiOperation(value = "补签", notes = "用户补签")
    public R insertSignByDay(@PathVariable("userId") Long userId,@PathVariable("day") Integer day) throws Exception {

        return signInStageService.insertSignByDay(userId, day);
    }

    /**
     * 获取今天所有签到的人数
     *
     * @throws Exception
     */
    @GetMapping("/sameday/signAmount")
    @ApiOperation(value = "系统日活统计", notes = "获取今天所有的签到人数")
    public R getAllSignAmountAtSameDay() throws Exception {

        return signInStageService.getAllSignAmountAtSameDay();
    }


    /**
     * 获取用户该月的签到次数
     *
     * @throws Exception
     */
    @GetMapping("/mothLive/{userId}")
    @ApiOperation(value = "某用户月活统计", notes = "获取用户该月的签到次数")
    public R getSignCountInMoth(@PathVariable("userId") Long userId) throws Exception {

        return signInStageService.getSignCount(userId);
    }


    /**
     * 获取的签到情况(以日历组件形式)
     *
     * @throws Exception
     */
    @GetMapping("/signInfo/{userId}")
    @ApiOperation(value = "某用户月内签到情况", notes = "获取的签到情况(以日历组件形式)")
    public R getSignInfoInMoth(@PathVariable("userId") Long userId) throws Exception {

        return signInStageService.getSignInfo(userId);
    }

    /**
     * 获取排行榜信息
     *
     * @throws Exception
     */
    @GetMapping("/rank")
    @ApiOperation(value = "获取排行榜信息", notes = "根据用户的签到次数作为排行榜的排序依据")
    public R getRankInfo() throws Exception {

        return signInStageService.getUsersSignAmountBySorted();
    }


}
